﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Parse.aspx.cs" Inherits="Cms.Web.CmsSystem.SysAdmin.FormSetting.Parse" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
        #page
        {
            position: relative;
            width: 960px;
            margin: 0 auto;
            border:1px solid Red;
        }
        .ctrl
        {
            font-size: 12px;
            position: absolute;
            border-color:#ace;
        }
    </style>
    <script type="text/javascript" src="../../../Scripts/jquery-1.8.0.min.js"></script>
    <script type="text/javascript">
        var ctrljson=<%= ctrljson%>;
        var ctrltype=<%= ctrltype%>;
        function GetControlType(type){
            var result="None";
            for(var i in ctrltype ){
                if(ctrltype[i]===type){
                    result =i;
                    break ;
                }
            }
            return result ;
        }
        function BuildControl(jsonctrl){
            var type=GetControlType(jsonctrl["type"]);
            var html="";
            switch(type){
                case "Label":
                    html="<Label></Label>";
                    break ;
                case "Panel":
                    html="<Div></Div>";
                    break ;
                case "Input":
                    html="<Input type='text'/>";
                    break ;
                case "Button":
                    html ="<Button></Button>";
                    break ;
            }
            if(html!=""){
                var ctrl=$(html).addClass("ctrl");
                for(var i in jsonctrl){
                    switch(i){
                        case "caption":
                            ctrl.text(jsonctrl[i]);
                            break;
                        case "style":
                            ctrl.css(jsonctrl[i]);
                            break ;
                        case "type":
                            break ;
                        case "enabled":
                            var disabled=!jsonctrl[i];
                            if(disabled)
                                ctrl.attr("disabled","disabled");
                            break ;
                        default:
                            ctrl.attr(i,jsonctrl[i]);
                            break ;
                    }
                }
                return ctrl;
            }
            return null;
        }
        function BuildControlList(jsonlist){
            var html=[];
            var t="";
            for(var i in jsonlist){
                var ctrl=jsonlist[i];
                t=BuildControl(ctrl);
                if(t){
                    $("#page").append(t);
                }
            }
        }
        $(function(){
            BuildControlList(ctrljson);
            var act="<%=Cms.EntLib.Request.GetString("action") %>";
            var formid="<%=Cms.EntLib.Request.GetString("formid")%>";
            var id= "<%=Cms.EntLib.Request.GetString("id")%>";
            if(act=="1"){
                $.ajax({
                    url:"FormHandler.ashx",
                    data:{action:"showinfo",formid:formid,id:id},
                    dataType:"json",
                    success:function(json){
                        for(var id in json){
                            var ctrl=$("[name="+id+"]");
                            if(ctrl.size()<1)
                                ctrl=$("[name="+id.toUpperCase()+"]");
                            if(ctrl.size()<1)
                                ctrl=$("[name="+id.toLowerCase()+"]");
                            if(ctrl.size()>0){
                                ctrl.val(json[id]);
                            }
                        }
                    }
                });
            }
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div id="page">
     <input type="submit" value="提交" />
    </div>
   
    </form>
</body>
</html>
